<template>
  <div>
    <div>
      <div class="grid-item"
        v-for="(item, index) in items"
        :key="index"
        @click="onClick(item, index)">
        <img ref="gridItemImg" :src="item.icon" alt="">
        <p>{{ item.name }}</p>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props:{
    items: {
      type: Array,
      default: function(){
        return [];
      }
    },
    onClick: {
      type: Function,
      default: function(){
        return function(){}
      }
    }
  },
  methods:{
    imgStyle(){
      let imgs = this.$refs.gridItemImg || [];
      // console.log(imgs, imgs[0].width);
      for(let i = 0; i < imgs.length; i++){
        imgs[i].height = imgs[i].width;
      }
    }
  },
  mounted(){
    this.imgStyle();
  }
}
</script>

<style scoped>
.grid-item{
  width: 25%;
  display: inline-block;
  text-align: center;
  background: #ffffff;
  padding: 1%;
  padding-top: 2%;
  box-sizing: border-box;
}
.grid-item img{
  width: 50%;
  display: inline-block;
}
.grid-item p{
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
}
</style>
